import java.util.Stack;

public class Text {
    public boolean IsPopOrder (int[] pushV, int[] popV) {
       int j = 0;
       Stack<Integer> stack = new Stack<>();
       for(int i = 0; i < pushV.length;i++){
           stack.push(pushV[i]);
           while (!stack.empty() && stack.peek() == popV[j]){
               stack.pop();
               j++;
           }
       }
       return stack.empty();
    }
    public static int evalRPN(String[] tokens) {
        Stack<Integer> stack = new Stack<>();
        for (int i = 0; i < tokens.length; i++) {
            String str = tokens[i];
            if (!str.equals("+") && !str.equals("-") && !str.equals("*") && !str.equals("/")) {
                stack.push(Integer.valueOf(str));
            }else {
                int b = stack.pop();
                int a = stack.pop();
                int val = 0;
                switch(str){
                    case "+":
                        val = a + b;
                        break;
                    case "-":
                        val = a - b;
                        break;
                        case "*":
                        val = a * b;
                        break;case "/":
                        val = a / b;
                        break;
                }
                stack.push(val);
            }
        }
        return stack.pop();
    }
    public static boolean isValid(String s) {

        Stack<Character> stack = new Stack<>();
        for (int i = 0; i < s.length(); i++) {
            char ch = s.charAt(i);
            if (ch == '[' || ch == '{' || ch == '(') {
                stack.push(ch);
            }
            if (ch == ']' || ch == '}' || ch == ')') {
                if (stack.empty()) {
                    return false;
                }else {
                    char chr = stack.pop();
                    if (chr == '(' && ch != ')' || chr == '{' && ch != '}' || chr == '['&& ch != ']') {
                        return false;
                    }
                }
            }
        }
        if (!stack.empty()) {
            return false;
        }
        return true;
    }

    public static void main(String[] args) {
        String[] str = {"2","1","+","3","*"};
        int val = evalRPN(str);
        System.out.println(val);
    }
}
